

from rest_framework import serializers
from django.contrib.auth.models import Permission,ContentType

class PermTypeModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = ContentType
        fields = [
            'id',
            'name'
        ]


class PermModelSerializer(serializers.ModelSerializer):
    # content_type = serializers.StringRelatedField() --> 默认StringRelatedField类型，只参与序列化
    class Meta:
        model = Permission
        fields = [
            'id',
            'name',
            'codename',
            'content_type' # 外间关联字段，默认就是PrimaryKeyRelatedField,参与反序列化
        ]